package logic

import (
	"context"
	"zy31/rpc/model/mysql"

	"zy31/rpc/internal/svc"
	"zy31/rpc/user"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserListLogic {
	return &UserListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserListLogic) UserList(in *user.UserListRequest) (*user.UserListResponse, error) {
	var users []mysql.User
	mysql.DB.Where("status=?", in.Status).Find(&users)
	var list []*user.UserList
	for _, m := range users {
		userList := user.UserList{
			Name:   m.Name,
			Tel:    m.Tel,
			Status: int64(m.Status),
		}
		list = append(list, &userList)
	}
	return &user.UserListResponse{
		List: list,
	}, nil
}
